﻿using System;
using System.Windows.Data;
using System.Text;
namespace ReflectionStudio.Controls
{
    /// <summary>
    /// Converter : Boolean to System.Windows.Visibility and not revert
    /// </summary>
    [ValueConversion(typeof(object), typeof(object))]
    public class BYTE2TR : IValueConverter
    {
        /// <summary>
        /// IValueConverter.Convert
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null)
                return "";
            byte[] b = value as byte[];
            System.Text.UnicodeEncoding converter = new System.Text.UnicodeEncoding();
            return converter.GetString(b);

        } 

        /// <summary>
        /// IValueConverter.ConvertBack (not implemented)
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string str = value as string;
            if (str == null)
                return null;
            byte[] b = Encoding.Default.GetBytes(str);
            System.Text.UnicodeEncoding converter = new System.Text.UnicodeEncoding(); 
            return converter.GetBytes(str);
        }
    }
}
